﻿Imports System.Collections.Generic
Imports System.Text
Imports Microsoft.VisualStudio.DebuggerVisualizers
Imports System.Windows.Forms
Imports System.Drawing

<Assembly: System.Diagnostics.DebuggerVisualizer(GetType(Visualizers.ImageVisualizer), GetType(VisualizerObjectSource), Target:=GetType(System.Drawing.Image), Description:="View the image in Seperate Window")> 
Namespace Visualizers
    Public Class ImageVisualizer
        Inherits DialogDebuggerVisualizer
        Protected Overrides Sub Show(windowService As IDialogVisualizerService, objectProvider As IVisualizerObjectProvider)
            Dim image As Image = DirectCast(objectProvider.GetObject(), Image)

            Dim Imgfrm As New Form()
            With Imgfrm
                .Text = String.Format("Image Viewer Width: {0}, Height: {1}", image.Width, image.Height)
                .ClientSize = New Size(image.Width, image.Height)
                .FormBorderStyle = FormBorderStyle.FixedToolWindow
                Dim Imagebox As New PictureBox()
                If .Size.Width < 50 Then
                    .Size = New Size(50, .Size.Width)
                    Imagebox.SizeMode = PictureBoxSizeMode.StretchImage
                End If
                If .Size.Height < 50 Then
                    .Size = New Size(.Size.Height, 50)
                    Imagebox.SizeMode = PictureBoxSizeMode.StretchImage
                End If
                Imagebox.Image = image
                Imagebox.Parent = Imgfrm
                Imagebox.Dock = DockStyle.Fill
            End With
            windowService.ShowDialog(Imgfrm)
        End Sub
    End Class
End Namespace